import { _decorator, Camera, Component, Node, RenderTexture, UITransform, view } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('cameraCtl')
export class cameraCtl extends Component {

    @property(Camera) mainCamera: Camera
    @property(Camera) rtCamera: Camera
    @property(RenderTexture) shadowRt: RenderTexture
    @property(Node) shadowNode: Node

    start() {
        if (this.mainCamera.orthoHeight != this.rtCamera.orthoHeight) {
            console.warn("camera error do fix...", this.mainCamera.orthoHeight, ": ", this.rtCamera.orthoHeight)
            this.rtCamera.orthoHeight = this.mainCamera.orthoHeight
        }

        //修正大小
        console.log("visible size:", view.getVisibleSize(), view.getViewportRect())
        // this.scheduleOnce(() => {
        // console.log("rt or size :", this.shadowRt.width, this.shadowRt.height)
        this.shadowRt.resize(view.getVisibleSize().width, view.getVisibleSize().height)
        this.shadowNode.getComponent(UITransform).setContentSize(view.getVisibleSize())
        //测试手动同步...


        // console.log("rt new size :", this.shadowRt.width, this.shadowRt.height, view.getVisibleSize().height)
        // this.shadowRt.reset({
        //     width: this.shadowRt.width,// view.getVisibleSize().width,
        //     height: this.shadowRt.height,//view.getVisibleSize().height,
        //     externalFlag: gfx.TextureFlagBit.NONE
        // })
        // }, 0.05)


    }

    update(deltaTime: number) {

    }
}


